/*
 * Date: 2013 05 24 - Dương
 */

/*Banner Slide*/

$(function () {
    $('#banner .carousel').carousel({
        interval: 9000,
        speed: 1000,
        auto: true,
    }).on('slid', function () {
        var i = $(this).find('.active').index();
        switch (i) {
            case 0:
                $('.arrow').animate({left: 45}, 100);
                break;
            case 1:
                $('.arrow').animate({left: 196}, 100);
                break;
            case 2:
                $('.arrow').animate({left: 350}, 100);
                break;
            case 3:
                $('.arrow').animate({left: 505}, 100);
                break;
            case 4:
                $('.arrow').animate({left: 670}, 100);
                break;
        }
    });
    $('#partner .carousel').carousel({
        interval: false
    })
    $('#kh,#tv,#lt,.banner_menu').hover(function () {
        $('#banner .carousel').carousel('pause');
    }, function () {
        $('#banner .carousel').carousel('cycle');
    });
});

/*Hover khóa học #1*/

$(function () {
    $('.course_right_content').addClass('hidden');
    $('.course_right_block_list').addClass('hidden');

    $('.course_cover_button').click(function () {
        $(this).parent().addClass('hidden');
        $(this).parent().parent().children('.course_right_content').removeClass('hidden');
    });

    var timer;
    $('.course_right_block').hover(
            function () {
                var $this = $(this);
                timer = setTimeout(function () {
                    $this.children('.course_right_block_content').addClass('hidden');
                    $this.children('.course_right_block_list').removeClass('hidden');
                }, 1000);
            },
            function () {
                var $this = $(this);
                clearTimeout(timer);
                $this.children('.course_right_block_list').addClass('hidden');
                $this.children('.course_right_block_content').removeClass('hidden');
            }
    );

    /*scroll like facebook*/
//	$('.scroll-pane').jScrollPane({
//		horizontalGutter:5,
//		verticalGutter:5,
//		showArrows: false,
//		autoReinitialise: true
//	});
    $('.jspDrag').hide();
    $('.jspScrollable').mouseenter(function () {
        $(this).find('.jspDrag').stop(true, true).fadeIn('slow');
    });
    $('.jspScrollable').mouseleave(function () {
        $(this).find('.jspDrag').stop(true, true).fadeOut('slow');
    });
});

/*Hover khóa học #2*/
$(function () {
    $('.course_title').click(function () {
        console.log($(this).attr('class'));
    });

    var $color_theme = '';

    $('.lesson-title').popover({
        html: true,
        trigger: 'click',
        delay: {
            show: 500,
            hide: 2000,
            container: 'body',
            delay: {show: 1000, hide: 500}
        },
        placement: 'top'
    });

    $('#home_block2_left .lesson-title').hover(
            function () {
                $color_theme = $(this).parent().parent().children('.course_title').attr('class');
                $color_theme = 'bg_' + $color_theme.replace('course_title ', '');
                $(this).addClass($color_theme);
                $(this).addClass('white');
                //hide all other popover
                $.each($(this).parent().parent().siblings(), function () {
                    $.each($(this).find('.popover'), function () {
                        $(this).prev().popover('hide');
                    });
                });
                $(this).siblings().popover('hide');
                $(this).popover('show');
            },
            function () {

                $(this).removeClass($color_theme);
                $(this).removeClass('white');
                //$(this).popover('hide');
            }
    );

    $('#home_block2_left').mouseleave(function () {
        $(this).find('.popover').prev().popover('hide');
    });

    $('.comment-reply-toggle').toggle(
            function () {
                $(this).parent().parent().children('.comment-reply').show(400);
            }, function () {
        $(this).parent().parent().children('.comment-reply').hide(400);
    }
    );
});